/**
  ******************************************************************************
  * @file    CFG_SetNetworkParameters.c
  * @author  exatron
  * @version V1.0.0
  * @date    segunda, 22 de dezembro de 2014
  * @brief   Função para setar parâmetros de rede.
  ******************************************************************************
  * @attention
  *
  *
  ******************************************************************************
  */

/**
  * @addtogroup CFG
  * @{
  */

/* Includes ------------------------------------------------------------------*/
#include <common.h>
#include <stdlib.h>

/* External functions --------------------------------------------------------*/

/**
  * @defgroup CFG_Functions
  * @{
  */

/**
  * @brief  Função para setar parâmetros de rede.
  * @param  NetworkType_t type: DHCP ou Static
  * @param  char *ip
  * @param  char *netmask
  * @param  char *gateway
  * @retval Devolve pela serial Result_t
  */
void CFG_SetNetworkParameters(NetworkType_t type, char *ip, char *netmask, char *gateway)
{
	if(type == DHCP_NETWORK)
	{
		aux_FileWrLine(PATH_CONF, "network", aux_itoa(DHCP_NETWORK), "Erro setando network\r\n");
		aux_FileWrLine(PATH_CONF, "ip", aux_itoa(Result_Error), "Erro setando ip\r\n");
		aux_FileWrLine(PATH_CONF, "netmask", aux_itoa(Result_Error), "Erro setando netmask\r\n");
		aux_FileWrLine(PATH_CONF, "gateway", aux_itoa(Result_Error), "Erro setando gateway\r\n");
	}
    /* Verifica ip */
	else if(strcntc(ip,'.') < 3)
	{
    	aux_USART0_puts("%s=%d\r\n", "CFG_SNP", Result_BadArgument);
    	aux_SetBusy(FALSE);
    	return;
	}
    /* Verifica netmask */
	else if(strcntc(netmask,'.') < 3)
	{
    	aux_USART0_puts("%s=%d\r\n", "CFG_SNP", Result_BadArgument);
    	aux_SetBusy(FALSE);
    	return;
	}
    /* Verifica gateway */
	else if(strcntc(gateway,'.') < 3)
	{
    	aux_USART0_puts("%s=%d\r\n", "CFG_SNP", Result_BadArgument);
    	aux_SetBusy(FALSE);
    	return;
	}
	else
	{
		aux_FileWrLine(PATH_CONF, "network", aux_itoa(STATIC_NETWOTK), "Erro setando network\r\n");
		aux_FileWrLine(PATH_CONF, "ip", ip, "Erro setando ip\r\n");
		aux_FileWrLine(PATH_CONF, "netmask", netmask, "Erro setando netmask\r\n");
		aux_FileWrLine(PATH_CONF, "gateway", gateway, "Erro setando gateway\r\n");
	}

	aux_USART0_puts("%s=%d\r\n", "CFG_SNP", Result_Ok);

	aux_SetBusy(FALSE);
}

/**
  * @}
  */

/**
  * @}
  */



